/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pig.myvideos.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.myvideos.entity.Myvideos;
import com.pig4cloud.pig.myvideos.service.MyvideosService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;


/**
 * 视频管理
 *
 * @author pig code generator
 * @date 2021-12-09 15:18:26
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/myvideos" )
@Api(value = "myvideos", tags = "视频管理管理")
public class MyvideosController {

    private final  MyvideosService myvideosService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param myvideos 视频管理
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('myvideos_myvideos_get')" )
    public R getMyvideosPage(Page page, Myvideos myvideos) {
        return R.ok(myvideosService.page(page, Wrappers.query(myvideos)));
    }


    /**
     * 通过id查询视频管理
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('myvideos_myvideos_get')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(myvideosService.getById(id));
    }

    /**
     * 新增视频管理
     * @param myvideos 视频管理
     * @return R
     */
    @ApiOperation(value = "新增视频管理", notes = "新增视频管理")
    @SysLog("新增视频管理" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('myvideos_myvideos_add')" )
    public R save(@RequestBody Myvideos myvideos) {
        return R.ok(myvideosService.save(myvideos));
    }

    /**
     * 修改视频管理
     * @param myvideos 视频管理
     * @return R
     */
    @ApiOperation(value = "修改视频管理", notes = "修改视频管理")
    @SysLog("修改视频管理" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('myvideos_myvideos_edit')" )
    public R updateById(@RequestBody Myvideos myvideos) {
        return R.ok(myvideosService.updateById(myvideos));
    }

    /**
     * 通过id删除视频管理
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除视频管理", notes = "通过id删除视频管理")
    @SysLog("通过id删除视频管理" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('myvideos_myvideos_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(myvideosService.removeById(id));
    }

	@ApiOperation(value = "新增视频管理", notes = "新增视频管理")
	@SysLog("新增视频管理" )
	@PostMapping("/saveAll")
	public R saveAll(@RequestParam("file") MultipartFile files,
					 String myVideoClass, String myTagsCn) {
		boolean ret = myvideosService.saveAll(files, myVideoClass, myTagsCn);
		return R.ok(ret);
	}

	@ApiOperation(value = "发布视频号", notes = "发布视频号")
//	@SysLog("发布视频号" )
	@PostMapping("/FabuShipinhao")
	public R FabuShipinhao(String jId) {
		boolean ret = myvideosService.FabuShipinhao(jId);
		return R.ok(ret);
	}

	@ApiOperation(value = "发布抖音", notes = "发布抖音")
//	@SysLog("发布视频号" )
	@PostMapping("/FabuDouyin")
	public R FabuDouyin(String jId) {
		boolean ret = myvideosService.FabuDouyin(jId);
		return R.ok(ret);
	}

	@ApiOperation(value = "爬取视频", notes = "爬取视频")
//	@SysLog("爬取视频")
	@PostMapping("/crawlVideo")
	public R crawlVideo() {
		boolean ret = myvideosService.crawlVideo();
		return R.ok(ret);
	}

	@ApiOperation(value = "android2pc", notes = "android2pc")
//	@SysLog("android2pc")
	@PostMapping("/android2pc")
	public R android2pc() {
		boolean ret = myvideosService.android2pc();
		return R.ok(ret);
	}
}
